#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <algorithm>
using namespace std;
struct Stu
{
    int a;
    int b;
    int c;
}s[1000];
bool cmp(Stu x, Stu y)
{
    return x.b < y.b;
}
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &s[i].a, &s[i].b, &s[i].c);
    }
    int m;
    scanf("%d", &m);
    int q[1000];
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &q[i]);
    }
    sort(s, s + n, cmp);
    for (int i = 0; i < m; i++)
    {
        printf("%d %d\n", s[q[i] - 1].a, s[q[i] - 1].c);
    }
    return 0;
}